package com.gviiii.baiduai.ai;

import com.gviiii.baiduai.config.ServiceConfig;
import com.gviiii.baiduai.pojo.FileInfo;
import com.gviiii.baiduai.pojo.ImageResultInfo;
import com.gviiii.baiduai.util.DateUtil;
import com.gviiii.baiduai.util.FileUtil;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractAiItemService extends AbstractAiService {

    public AbstractAiItemService() {
    }

    /**
     * @param serviceConfig
     * @param fileInfo
     * @param resultsBean
     * @param i
     */
    @Override
    public void switchImgsDir(ServiceConfig serviceConfig, FileInfo fileInfo, ImageResultInfo.ResultsBean resultsBean, int i) {
        switch (resultsBean.getName()) {
            case "xinzeng":
                try {
                    LocalDateTime dateTime = DateUtil.createDateTimeByInstant(Files.getLastModifiedTime(Paths.get(fileInfo.getFilePath())).toInstant());
                    System.out.println("图片:" + fileInfo.getFilePath() + " 位置: " + resultsBean.getLocation() + " 时间: " + DateUtil.formatDateTime(dateTime, "yyyy-MM-dd HH:mm:ss") + " 放置时间超过 " + DateUtil.dissimilarityByHours(LocalDateTime.now(), dateTime) + " 小时 是障碍物");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                createImageFile(serviceConfig.getResultMap(),fileInfo,resultsBean, i);
                break;
            default:
                createImageFile(serviceConfig.getResultMap(),fileInfo,resultsBean,i);
                break;
        }
    }

    /**
     * @param fileInfo
     * @param api
     * @param threshold
     */
    @Override
    protected void distinguish(FileInfo fileInfo, String api, double threshold) {
        Map<String,Object> map = new HashMap<>();
        map.put("image", FileUtil.encodeFiles(fileInfo.getFilePath()));
        map.put("threshold", threshold);
        distinguish(map);
    }


}
